local mingjian = fk.CreateSkill {

  name = "joy__mingjian",

  tags = {  },

}



mingjian:addEffect("active", {
  name = "joy__mingjian",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(mingjian.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = effect.cards
    local dummy = Fk:cloneCard("dilu")
    room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, mingjian.name, nil, false)
    room:addPlayerMark(target, "@@" .. mingjian.name, 1)
  end,
})

mingjian:addEffect(fk.TurnStart, {
  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@@joy__mingjian") > 0 and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@@joy__mingjian-turn", player:getMark("@@joy__mingjian"))
    room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, player:getMark("@@joy__mingjian"))
    room:setPlayerMark(player, "@@joy__mingjian", 0)
  end,
})

mingjian:addEffect("targetmod", {
  name = "#joy__mingjian_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("@@joy__mingjian-turn") > 0 and scope == Player.HistoryPhase then
      return player:getMark("@@joy__mingjian-turn")
    end
  end,
})

return mingjian